import {defineStore} from 'pinia';
import {forEach} from "lodash-es";

export interface TabInfo{
    openTab:string[],
    activeIndex:string,
}
const useTabStore = defineStore({
    id:'tab',
    state:():Partial<TabInfo>=>({
        openTab:[],
        activeIndex:'/#/admin'
    }),
    actions:{
        add_tab(url:string){
            for(let i=0;i<this.openTab!.length;i++){
                if(url==this.openTab![i]){
                    this.activeIndex=url;
                    return;
                }
            }
            this.openTab?.push(url);
            this.activeIndex=url;
        },
        del_tab(url:string){
            let index=0;
            for(let option of this.openTab!){
                if(option===url){
                    break;
                }
                index++;
            }
            this.openTab!.splice(index,1);
            if(this.openTab!.length>=1){
                this.activeIndex==this.openTab![0];
            }
        },
        set_active(url:string){
            this.activeIndex==url;
        }
    }
});

export default  useTabStore;